<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="org.json.*"%>
<%@ page import="org.jbpm.graph.def.*"%>
<%@ page import="org.jbpm.graph.exe.*"%>
<%@ page import="org.jbpm.taskmgmt.def.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.el.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.sys.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.util.*"%>
<%@ page import="com.gzgi.workflow.jbpm.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.context.*"%>
<%@ page import="com.gzgi.workflow.jbpm.config.*"%>
<%@ page import="com.gzgi.workflow.jbpm.container.*"%>
<%@ page import="com.gzgi.workflow.jbpm.datafield.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.product.*"%>
<%

	ProductController handler = (ProductController)ControllerFactory.getController("productController");
   
    String productId = request.getParameter("productId");

	boolean showConfirm = false;

	Product product = handler.getProduct(productId);
	if(product == null ){
		 product = new Product();
		 showConfirm = false;
	} else {
		String actorId = (String)session.getAttribute(SecurityContext.LOGIN_ACTOR_ID);
		ProcessContainer  container = ProcessContainer.getContainer();
		Collection  processInstanceIds = container.getRunningProcessInstanceIds(actorId);
		if(product.getProcessInstanceId() != null){
            if(processInstanceIds.contains(product.getProcessInstanceId())){
				showConfirm = true;
			}
		} else {
			showConfirm = true;
		}
	}
%>
<%@ include file="/pages/tm/header.jsp"%>
<link type="text/css"
	href="<%=request.getContextPath()%>/scripts/calendar/skins/aqua/theme.css"
	rel="stylesheet" />
<script src="<%=request.getContextPath()%>/scripts/calendar/calendar.js"
	language="javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/calendar/lang/calendar-zh.js"
	language="javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/calendar/calendar-setup.js"
	language="javascript"></script>

<script language="JavaScript">

 Ext.onReady(function(){
   
   if(Ext.get('confirm') != null){
	   Ext.get('confirm').on('click', function(e){

		var productName = document.getElementById("productName").value;
		if( productName == ""){
              Ext.MessageBox.alert(' 警告 ', '  \n请填写产品名称。', null);
			  return;
		}

		var productCode = document.getElementById("productCode").value;
		if( productCode == ""){
              Ext.MessageBox.alert(' 警告 ', '  \n请填写产品代码。', null);
			  return;
		}

		var productDate = document.getElementById("productDate").value;
		if( productDate == ""){
              Ext.MessageBox.alert(' 警告 ', '  \n请选择生产日期。', null);
			  return;
		}
 
        Ext.MessageBox.show({
           title:'保存数据?',
           msg: '准备保存数据，确认吗？',
           buttons: Ext.MessageBox.OKCANCEL,
           fn: submitRequest,
		   animEl: 'confirm',
           icon: Ext.MessageBox.WARNING
       });
    });
   }

 if(Ext.get('submitXY') != null){
      Ext.get('submitXY').on('click', function(e){
        Ext.MessageBox.show({
           title:'提交审核?',
           msg: '准备提交审核，确认吗？',
           buttons: Ext.MessageBox.OKCANCEL,
           fn: submitXY,
		   animEl: 'submitXY',
           icon: Ext.MessageBox.WARNING
       });
    });
 }

  function submitRequest(btn) {
	  if(btn == 'ok'){		 
 			document.typeForm.submit();
	    }
    }

  function submitXY(btn) {
	  if(btn == 'ok'){		
		    var isAgree = document.getElementById("isAgree").value;
			if(isAgree == 'false'){
				var opinion = document.getElementById("opinion").value;
				if(opinion == ""){
                    Ext.MessageBox.alert(' 警告 ', '  \n审核不通过请填写不通过原因。', null);
			        return;
				}
			}
		    document.typeForm.action="productSubmit.jsp"
 			document.typeForm.submit();
	    }
    }

  });

  function isAgreeX(isAgree){
	   document.getElementById("isAgree").value=isAgree;
  }

</script>

<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<center><br>
<br>
<form name="typeForm" method="post" action="productSave.jsp"
	class="x-form"><input type="hidden" id="productId"
	name="productId"
	value="<%=product.getProductId() != null ? product.getProductId() : ""%>">
<input type="hidden" id="isAgree" name="isAgree" value="true">

<div style="width: 75%;" align="center">
<div class="x-box-tl">
<div class="x-box-tr">
<div class="x-box-tc"></div>
</div>
</div>
<div class="x-box-ml">
<div class="x-box-mr">
<div class="x-box-mc">
<h3 style="margin-bottom: 5px;"><img
	src="<%=request.getContextPath()%>/pages/images/window.png" alt="产品信息">&nbsp;产品信息</h3>

<div class="x-form-bd" id="container">

<fieldset class="x-fieldset"><legend>基本属性</legend> <br>
<table class="table-border" align="center" cellpadding="4"
	cellspacing="1">
	<tbody>
		<tr>
			<td height="26" valign="top" align="left" width="20%">产品名称(*)</td>
			<td height="26" valign="top" align="left" width="80%"><input
				id="productName" name="productName" size="50" type="text"
				value="<%=product.getProductName() != null ? product.getProductName() : ""%>"
				class="x-form-text " valign="top" /></td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">产品代码(*)</td>
			<td height="26" valign="top" align="left"><input
				id="productCode" name="productCode" size="50" type="text"
				value="<%=product.getProductCode() != null ? product.getProductCode() : ""%>"
				class="x-form-text " valign="top" /></td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">厂商</td>
			<td height="26" valign="top" align="left"><input
				id="manufacturer" name="manufacturer" size="50" type="text"
				value="<%=product.getManufacturer() !=null ? product.getManufacturer() : ""%>"
				class="x-form-text " valign="top" /></td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">单价</td>
			<td height="26" valign="top" align="left"><input id="price"
				name="price" size="50" type="text" value="<%=product.getPrice()%>"
				class="x-form-text " valign="top" /></td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">数量</td>
			<td height="26" valign="top" align="left"><input id="quantity"
				name="quantity" size="50" type="text"
				value="<%=product.getQuantity()%>" class="x-form-text " valign="top" />
			</td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">生产日期(*)</td>
			<td height="26" valign="top" align="left"><input
				id="productDate" name="productDate" size="50" type="text"
				value="<%=DateTools.getDate(product.getProductDate())%>"
				class="x-form-text " valign="top" /> &nbsp;<img
				src="<%=request.getContextPath()%>/pages/images/calendar.gif"
				id="f_trigger_1" style="cursor: pointer; border: 1px solid red;" />
			</td>
		</tr>
		<%if(product.getProcessInstanceId() != null && showConfirm && product.getStatus() != -1){%>
		<tr>
			<td height="26" valign="top" align="left">是否通过</td>
			<td height="26" valign="top" align="left">通过 <input type="radio"
				id="isAgreeXY" name="isAgreeXY" value="true"
				onclick="javascript:isAgreeX('true');" checked> 不通过<input
				type="radio" id="isAgreeXY" name="isAgreeXY" value="false"
				onclick="javascript:isAgreeX('false');"></td>
		</tr>
		<tr>
			<td height="26" valign="top" align="left">审核意见</td>
			<td height="26" valign="top" align="left"><textarea id="opinion"
				name="opinion" rows="10" cols="62" class="x-form-field"></textarea>
			</td>
		</tr>
		<%}%>
	</tbody>
</table>

</fieldset>

</div>

<div align="center"><br />
<%if( product.getStatus() <= 0  ){%> <input value="保 存" class="button"
	id="confirm" name="confirm" type="button"> <%}%> <%if(product.getProcessInstanceId() != null && showConfirm){%>
<input value="确 定" class="button" id="submitXY" name="submitXY"
	type="button"> <%}else if(product.getProductId() != null && product.getProcessInstanceId() == null){%>
<input type="hidden" id="actionType" name="actionType"
	value="startProcess"> <input value="提 交" class="button"
	id="submitXY" name="submitXY" type="button"> <%}%> <input
	value="返 回" class="button" id="back" name="back" type="button"
	onclick="history.back();"> <br />
<br />
</div>

</div>
</div>
</div>
<div class="x-box-bl">
<div class="x-box-br">
<div class="x-box-bc"></div>
</div>
</div>
</div>
</form>
</center>

<script type="text/javascript">
    try{
		Calendar.setup({
					inputField     :    "productDate",     // id of the input field
					ifFormat       :    "%Y-%m-%d",      // format of the input field
					button         :    "f_trigger_1",  // trigger for the calendar (button ID)
					align          :    "Bl",           // alignment (defaults to "Bl")
					singleClick    :    true,
					showsTime      :    false
			});
    }catch(exe){
    }
</script>